﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UCF.Core.Forms
{
    public static class ExMethodForOpenFileDialog
    {
        /// <summary>
        /// 获取有效的文件名
        /// </summary>
        /// <param name="ofd"></param>
        /// <param name="ext">txt files (*.txt)|*.txt|All files (*.*)|*.*</param>
        /// <returns></returns>
        public static string GetFileName(this OpenFileDialog ofd, string ext = "All files (*.*)|*.*")
        {
            if (ext.Length > 0)
            {
                ofd.Filter = ext;
                ofd.FileName = string.Empty;
            }
            if (DialogResult.OK != ofd.ShowDialog()) return string.Empty;
            return ofd.FileName;
        }
    }
}
